<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['link_index_mb_specialad'];?></h3>
      <ul class="tab-base">
        <li><a href="index.php?act=mb_specialad&op=mb_specialad_list" ><span><?php echo $lang['nc_manage'];?></span></a></li>
        <li><a href="index.php?act=mb_specialad&op=mb_specialad_add" ><span><?php echo $lang['nc_new'];?></span></a></li>
        <li><a href="JavaScript:void(0);" class="current"><span><?php echo $lang['nc_edit'];?></span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="link_form" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="id" value="<?php echo $output['link_array']['id'];?>" />
    <table class="table tb-type2">
      <tbody>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="spad_title">请推荐位标题</td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['spad_title'];?>" name="spad_title" id="spad_title" class="txt"></td>
          <td class="vatop tips">请输入推荐位标题</td>
        </tr>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="spad_code">推荐位编号</td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['spad_code'];?>" name="spad_code" id="spad_code" class="txt"></td>
          <td class="vatop tips">请输入推荐位编号</td>
        </tr>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="spad_spec">图片规格</td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['spad_spec'];?>" name="spad_spec" id="spad_spec" class="txt"></td>
          <td class="vatop tips">请输入图片规格</td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for=""><?php echo $lang['link_index_pic_sign'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <span class="type-file-show">
            <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
            <div class="type-file-preview">
              <img src="<?php echo UPLOAD_SITE_URL.DS.ATTACH_MOBILE.'/spad/'.$output['link_array']['spad_img'];?>"></div>
            </span>
            <span class="type-file-box">
            <input name="spad_img" type="file" class="type-file-file" id="spad_img" size="30">
            </span>
          </td>
          <td class="vatop tips"><?php if($output['link_array']['spad_img'] != ''){ ?>
            <?php } else { echo "<span class='red'>".$lang['link_add_tosign']."</span>"; } ?></td>
        </tr>
        <tr>
          <td colspan="2" ><label for="spad_url">链接地址:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <input type="text" name="spad_url" id="spad_url" value="<?php echo $output['link_array']['spad_url'];?>" class="txt" >
          </td>
          <td class="vatop tips">指向外部链接时填写，否则不填写</td>
        </tr>
        <!-- 20170104周家财修该 -->
        <tr>
          <td colspan="2" ><label for="spad_id">广告类型ID:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <input type="text" name="spad_id" id="spad_id" value="<?php echo $output['link_array']['spad_id'];?>" class="txt" >
          </td>
          </tr>
          <tr class='gc_td'>
          <td  colspan="2" ><label for="spad_id">商品分类ID:</label></td>
        </tr>
          <tr class='gc_td'>
           <td  class="vatop rowform">
            <input type="text" name="gc_id" id="gc_id" value="<?php echo $output['link_array']['gc_id'];?>" class="txt" >
          </td>
          
          <td class="vatop tips">指向商品链接时填写商品ID，否则填写0;指向商品分类列表的时候写3，并写入商品分类id</td>
        </tr>
        <!-- 20170104周家财修该 -->
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="spad_name"><?php echo $lang['link_index_title'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['spad_name'];?>" name="spad_name" id="spad_name" class="txt"></td>
          <td class="vatop tips"><?php echo $lang['link_add_name'];?></td>
        </tr>
        <tr>
          <td colspan="2" ><label for="spad_price">价格:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <input type="text" name="spad_price" id="spad_price" value="<?php echo $output['link_array']['spad_price'];?>" class="txt" >
          </td>
          <td class="vatop tips">价格</td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for="spad_order"><?php echo $lang['nc_sort'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['link_array']['spad_order'];?>" name="spad_order" id="spad_order" class="txt"></td>
          <td class="vatop tips"><?php echo $lang['link_add_sort_tip'];?></td>
        </tr>
      <tfoot>
        <tr class="tfoot">
          <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<script type="text/javascript">

//按钮先执行验证再提交表单
$(function(){$("#submitBtn").click(function(){
    if($("#link_form").valid()){
     $("#link_form").submit();
	}
	});
});
//
$(document).ready(function(){
	if($("#spad_id").val()==3){
		$('.gc_td').show();
	}else{
		$('#gc_id').val('');
		$('.gc_td').hide();
	}
	$("#spad_id").blur(function(){
	    //这就是输入值的个数
	    //var length=this.value.length;
	    var val=$(this).val();
	    if(val==3){
	    	$('.gc_td').show();
		}else{
			$('#gc_id').val('');
			$('.gc_td').hide();
		}
	     
	});
	
	$('#link_form').validate({
        errorPlacement: function(error, element){
			error.appendTo(element.parent().parent().prev().find('td:first'));
        },
        rules : {
            spad_title : {
                required : true
            },
            spad_code : {
                required : true
            },
            spad_name : {
                required : true
            },
            /*link_url  : {
                required : true,
                url      : true
            },*/
            spad_order : {
                number   : true
            }
        },
        messages : {
            spad_title : {
                required : '推荐位标题不能为空'
            },
            spad_code : {
                required : '推荐位编号不能为空'
            },
            spad_name : {
                required : '<?php echo $lang['link_add_title_null'];?>'
            },
            /*link_url  : {
                required : '<?php echo $lang['link_add_url_null'];?>',
                url      : '<?php echo $lang['link_add_url_wrong'];?>'
            },*/
            spad_order  : {
                number   : '<?php echo $lang['link_add_sort_int'];?>'
            }
        }
    });
});
</script> 
<script type="text/javascript">
$(function(){
    var textButton="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
	$(textButton).insertBefore("#spad_img");
	$("#spad_img").change(function(){
	$("#textfield1").val($("#spad_img").val());
});
});
</script>
